
<%@ page language="java" %>

<%@ page import="java.util.List,
                java.util.ArrayList,
                java.util.Iterator,
                com.scalar.chiptrack.utils.StringUtils,
                com.scalar.chiptrack.commons.Address,
                com.scalar.chiptrack.operations.packingslip.forms.PackingSlipForm,
                com.scalar.chiptrack.sales.SalesOrder,
                com.scalar.chiptrack.sales.LineItem,
                com.scalar.chiptrack.utils.ConfigManager,
                org.apache.struts.util.LabelValueBean,
                com.scalar.chiptrack.users.Functionality,
                com.scalar.chiptrack.users.User,
                com.scalar.chiptrack.commons.Constants,
                com.scalar.chiptrack.commons.SessionKeys" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/commercialInvoice.do"/>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
<% User user1 = (User)session.getAttribute (SessionKeys.USER_KEY); %>

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<BODY bgColor='#ffffff' leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">

<SCRIPT language="JavaScript">

function loadPackingSlipsBySalesOrder()
{
    document.commercialInvoiceForm.poSalesOrderId.value = document.commercialInvoiceForm.salesOrderId.value;
    //alert ('sales order id = ' + document.commercialInvoiceForm.salesOrderId.value)
    if( document.commercialInvoiceForm.salesOrderId.value != -1 )
    {
        document.commercialInvoiceForm.action = '<%=chipTracContext%>/commercialInvoice.do?action=loadPackingSlips';
        document.commercialInvoiceForm.submit();
    }
}

function loadPackingSlipsByPoSalesOrder()
{
    document.commercialInvoiceForm.salesOrderId.value = document.commercialInvoiceForm.poSalesOrderId.value;
    //alert ('sales order id = ' + document.commercialInvoiceForm.salesOrderId.value)
    if( document.commercialInvoiceForm.salesOrderId.value != -1 )
    {
        document.commercialInvoiceForm.action = '<%=chipTracContext%>/commercialInvoice.do?action=loadPackingSlips';
        document.commercialInvoiceForm.submit();
    }
}

function loadInvoiceByPO()
{
    document.commercialInvoiceForm.salesOrderId.value = document.commercialInvoiceForm.poSalesOrderId.value;

    if( ( document.commercialInvoiceForm.salesOrderId.value != -1 ) && ( document.commercialInvoiceForm.customerShippingId.value != -1 ) )
    {
        document.commercialInvoiceForm.action = '<%=chipTracContext%>/commercialInvoice.do?action=loadInvoice';
        document.commercialInvoiceForm.submit();
    }
}


function loadInvoiceBySalesOrder() {

    document.commercialInvoiceForm.poSalesOrderId.value = document.commercialInvoiceForm.salesOrderId.value;

    if( ( document.commercialInvoiceForm.salesOrderId.value != -1 ) && ( document.commercialInvoiceForm.customerShippingId.value != -1 ) )
    {
        document.commercialInvoiceForm.action = '<%=chipTracContext%>/commercialInvoice.do?action=loadInvoice';
        document.commercialInvoiceForm.submit();
    }
}

function loadInvoice( customerShippingId )
{
    document.commercialInvoiceForm.customerShippingId.value = customerShippingId;
    // added by Murali Krishna, on 9 Feb 2005, useful when sample sales orders does not have customer PO numbers
    document.commercialInvoiceForm.poSalesOrderId.value = document.commercialInvoiceForm.salesOrderId.value;
    if( ( document.commercialInvoiceForm.salesOrderId.value != -1 ) && ( document.commercialInvoiceForm.customerShippingId.value != -1 ) )
    {
        document.commercialInvoiceForm.action = '<%=chipTracContext%>/commercialInvoice.do?action=loadInvoice';
        document.commercialInvoiceForm.submit();
    }
}

function deleteInvoice( customerShippingId )
{
    document.commercialInvoiceForm.customerShippingId.value = customerShippingId;
    // added by Murali Krishna, on 9 Feb 2005, useful when sample sales orders does not have customer PO numbers
    document.commercialInvoiceForm.poSalesOrderId.value = document.commercialInvoiceForm.salesOrderId.value;

    if( document.commercialInvoiceForm.customerShippingId.value != -1 )
    {   // changed by hareesh on 28th Julye 2003
        // -- START --
        //document.commercialInvoiceForm.action = '<%=chipTracContext%>/commercialInvoice.do?action=delete';
        // -- END ---
        document.commercialInvoiceForm.action = '<%=chipTracContext%>/commercialInvoice.do?action=deleteConfirm';
        document.commercialInvoiceForm.submit();
    }
}


// Balaram, June 24, 2003
function submitPage()
{
   /*
	*	Added by Vasanth Tatta 07/14/2003 .....
	*	Script validation to check whether the user entered or selected any criteria
	*	If none of the options were choosen then script throws an error message
	*/

	if( (document.commercialInvoiceForm.salesOrderNumber.value.length == 0 && document.commercialInvoiceForm.salesOrderId.value==-1)) {
		document.commercialInvoiceForm.txtErrMsg.value = ' Please choose or select a criteria to search';
		return false;
	}

	if( document.commercialInvoiceForm.salesOrderNumber.value.length != 0 )   // Load Invoice by Sales Order Number
    {
		for( i=0; i < document.commercialInvoiceForm.salesOrderId.length; i++ )
        {
            if( document.commercialInvoiceForm.salesOrderId.options[i].innerText != -1 )
            {
                if ( document.commercialInvoiceForm.salesOrderNumber.value.toLowerCase() == document.commercialInvoiceForm.salesOrderId.options[i].innerText.toLowerCase() )
                {
                    document.commercialInvoiceForm.salesOrderId.value = document.commercialInvoiceForm.salesOrderId.options[i].value;
                    document.commercialInvoiceForm.poSalesOrderId.value = document.commercialInvoiceForm.salesOrderId.options[i].value;
					//alert('loadPackingSlipsBySalesOrder');
                    loadPackingSlipsBySalesOrder();
                    return ;
                }
            }
        }


		//	Modified by Vasanth, 07/14/2003...
		//  Error message has been changed

        document.commercialInvoiceForm.txtErrMsg.value = 'Commercial Invoice is not available for the Sales Order Number: ' + document.commercialInvoiceForm.salesOrderNumber.value;
		document.commercialInvoiceForm.salesOrderNumber.focus();
		return false;
	}
    else if( document.commercialInvoiceForm.poSalesOrderId.value != -1 )      // load by Customer PO Number
    {
		loadPackingSlipsByPoSalesOrder();
    }
    else if( document.commercialInvoiceForm.salesOrderId.value != -1 )        // load by Sales Order ID
    {
		loadPackingSlipsBySalesOrder();
    }
}

function setCustomerPO()
{
    document.commercialInvoiceForm.poSalesOrderId.value = document.commercialInvoiceForm.salesOrderId.value;
    refreshPage();
}

function setSalesOrderId()
{
    document.commercialInvoiceForm.salesOrderId.value = document.commercialInvoiceForm.poSalesOrderId.value;
    refreshPage();
}

function cancelAndGoBack()
{
    document.commercialInvoiceForm.action = '<%=chipTracContext%>/commercialInvoice.do';
    document.commercialInvoiceForm.submit();
}


// Balaram on July 29, 2003
function showErrorReportPage()
{
    newWindow = window.open ('<%=chipTracContext%>/reportProblem.do','reportProblem','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=no,width=750,height=400,resizable=no');
    newWindow.focus();
}

function refreshPage()
{
    document.commercialInvoiceForm.action = '<%=chipTracContext%>/commercialInvoice.do';
    document.commercialInvoiceForm.submit();
}

</SCRIPT>


<!-- Top Header Start-->
<%@include file="/jsp/includes/header.jsp"  %>
<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
	<td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

<!-- Side Navigation start -->
<%@include file="/jsp/operations/operations_menu.jsp" %>
<!-- end of the side navigations -->


<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=20></TD>
<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
<TD valign="top" width="100%">

<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR>


<!-- body starts -->

<center><span class="NArialW">Commercial Invoice Menu</span></center>

<html:form name="commercialInvoiceForm" type="com.scalar.chiptrack.operations.packingslip.forms.CommercialInvoiceForm" action="/commercialInvoice.do" onsubmit="javascript:return submitPage();">
<html:hidden name="commercialInvoiceForm" property="customerShippingId"/>

   <table border='0' width='90%' align='center' cellspacing='4' class='NArialL'>
        <!--Bhaskar added this scriptlet on 16 july 2003-->
        <%ArrayList packingSlipListCheck = (ArrayList) request.getAttribute ("packingSlipList");
          if( ( packingSlipListCheck != null ) && ( packingSlipListCheck.size() != 0 ) )
          {%>
            <% if ( !user1.isActionAllowed ( Functionality.COMMERCIAL_INVOICE,
             User.USER_ACTION_DELETE ) ) { %>
                <tr><td colspan='5'><font class='NArialS'><font color='blue'>
                You don't have rights to Remove this record from listing</font></td></tr>
            <% } } %>
        <tr><td colspan='5'><chiptrack:info styleClass='NArialL'/></td></tr>
        <tr><td colspan='5'><chiptrack:errors styleClass='NArialL'/></td></tr>
        <tr><td colspan='5' bgcolor='#FFFFFF'><INPUT align=left border=0 maxLength=100 name="txtErrMsg" size=100
            style="BACKGROUND-COLOR:#FFFFFF; BORDER-BOTTOM: thin; BORDER-LEFT-STYLE: none; BORDER-RIGHT-STYLE: none; BORDER-TOP: thin; CLEAR: none; COLOR: red;font-family: arial;font-size: 8pt;font-weight:bold " value="" readOnly/>
        </td></tr>

        <tr><td colspan='5'><img height=10 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></td></tr>

        <tr>
            <td width='15%' align='left' nowrap>Sales Order#:</td>
            <td width='30%'>

			<!-- Vasanth 09/25/2003	styleClass changed for both Sales Order# field and Customer PO#	-->

				<html:select name="commercialInvoiceForm" property="salesOrderId" onchange="setCustomerPO()" styleClass="txfield">
                <html:option value="-1">-- Select One --</html:option>
                <html:options collection="salesOrderList" property="value" labelProperty="label"/>
                </html:select>
            </td>

            <td width='10%'>&nbsp;</td>
            <td width='15%' align='left' nowrap>Customer PO#:</td>
            <td width='30%'>
                <html:select name="commercialInvoiceForm" property="poSalesOrderId" onchange="setSalesOrderId()" styleClass="txfield">
                <html:option value="-1">-- Select One --</html:option>
                <html:options collection="salesOrdercustomerPOList" property="value" labelProperty="label"/>
                </html:select>
            </td>
        </tr>

        <tr><td colspan='5'><img height=10 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></td></tr>
        <!-- Modifide by KumaraSwamy on 30th August, 2004-->
        <!--tr>
            <td width='15%' align='left' nowrap>Sales Order#:</td>
            <td width='30%'><input type=text name='salesOrderNumber' class='txfield'></td>
            <td colspan='3' align='left' nowrap>&nbsp;</td>
        </tr-->
        <input type=hidden name='salesOrderNumber' class='txfield'><!--This is for JavaSript Validations-->
        <!--End of the Modification by KumaraSwamy-->
        <tr><td colspan='5'><img height=20 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></td></tr>

        <tr><td colspan=5 align='center'>
        <chiptrack:restrictedLink functionality='<%=Functionality.COMMERCIAL_INVOICE%>' action='<%=User.USER_ACTION_VIEW%>' href='javascript:submitPage();' onmouseover="window.status='Click to Search for Commercial Invoice';return true" onmouseout="window.status='';return true">
        <input type=image border="0" src="<%=chipTracContext%>/jsp/includes/images/search.gif" width="53" height="17" title="Click here to Search for Commercial Invoice"></chiptrack:restrictedLink>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	    <%-- <a href="javascript:cancelAndGoBack();" onMouseOver="window.status='Click to go back to Commercial Invocie Menu';return true" onMouseOut="window.status='';return true"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif"></a>--%>
        <%--Modified by varma(19 jul 2004) --%>
        <a href="javascript:document:commercialInvoiceForm.reset();" onMouseOver="window.status='Click to Reset';return true" onMouseOut="window.status='';return true" title="Click here to Reset"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif"></a>
        </td></tr>

        <tr><td colspan='5'><img height=20 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></td></tr>

        <%
            ArrayList packingSlipList = (ArrayList) request.getAttribute ("packingSlipList");
            if( ( packingSlipList != null ) && ( packingSlipList.size() != 0 ) )
            {
        %>
            <tr><td colspan='5'>
            <table width='80%' border='1' bordercolor='silver' cellpadding='0' cellspacing='0' align='center' class='NArialL'>
            <tr bgcolor='#993333'>
                <td height='10%' width='20%' align='center'><font color='#FFFFFF'>Line#</font></td>
                <td width='40%' align='left'><font color='#FFFFFF'>&nbsp;&nbsp;&nbsp;Packing Slip Number</font></td>
                <td width='50%' align='center'><font color='#FFFFFF'>Action</font></td>
            </tr>

        <%
                String[] bgColor = { "#FFFFEE", "#DEE1E2" };
                int packingSlipListSize = packingSlipList.size();
                PackingSlipForm packingSlipForm = null;

                for( int i=0; i<packingSlipListSize; i++)
                {
                    packingSlipForm = ( PackingSlipForm ) packingSlipList.get( i );
        %>
                <tr bgcolor='<%=bgColor[i%2]%>'>
                    <td height='25' width='20%' align='center'><%=i+1%>.</td>
                    <td width='50%' align='left'>&nbsp;&nbsp;&nbsp;<%=packingSlipForm.getLabel()%></td>
                    <td width='30%' align='center'>
                        &nbsp;&nbsp;&nbsp;
                        <chiptrack:restrictedLink functionality='<%=Functionality.COMMERCIAL_INVOICE%>' action='<%=User.USER_ACTION_VIEW%>' href='<%="javascript:loadInvoice(" + packingSlipForm.getCustomerShippingId() + ");"%>' onmouseover="window.status='Click to View this Commercial Invoice';return true" onmouseout="window.status='';return true">
                        View</chiptrack:restrictedLink>
                        &nbsp;&nbsp;&nbsp;
                        <chiptrack:restrictedLink functionality='<%=Functionality.COMMERCIAL_INVOICE%>' action='<%=User.USER_ACTION_DELETE%>' href='<%="javascript:deleteInvoice(" + packingSlipForm.getCustomerShippingId() + ");"%>' onmouseover="window.status='Click to Remove this Commercial Invoice from listing ';return true" onmouseout="window.status='';return true">
                        Remove</chiptrack:restrictedLink>
                        &nbsp;&nbsp;&nbsp;
                    </td>
                </tr>
        <%
                }
        %>

            </table>
        </td></tr>

        <tr><td colspan='5'><img height=40 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></td></tr>

        <%
            }
        %>

    </table>


</html:form>

<!-- till here -->
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>

<!-- Footer starts here -->
<%@include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->

</body>
</html>